package cn.com.dycc.meeting_assist.meeting_room.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.meeting_assist.meeting_room.entity.Room;
import cn.com.dycc.meeting_assist.meeting_room.param.FindRoomParam;
import cn.com.dycc.meeting_assist.meeting_room.service.RoomNotFoundException;
import cn.com.dycc.meeting_assist.meeting_room.service.RoomService;
import cn.com.dycc.util.JsonObjectResult;


/**
 * 
 * Description: 会议室管理控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年10月25日 下午3:54:20.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/room")
public class RoomController extends BaseController{
	
	@Resource
	private RoomService roomService;
	
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addRoom(HttpServletRequest req,Room room){
		int n = roomService.addRoom(req, room);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteRoom(HttpServletRequest req,String room_id){
		int n = roomService.deleteRoom(req, room_id);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updateRoom(HttpServletRequest req,Room room){
		int n = roomService.updateRoom(req, room);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findRoom(HttpServletRequest req,String room_id){
		Room room = roomService.findRoomById(req, room_id);
		return new JsonObjectResult(room);
	}
	
	@RequestMapping("/param.do")
	@ResponseBody
	public JsonObjectResult paramRoom(HttpServletRequest req,FindRoomParam param){
		System.out.println("con="+param);
		List<Room> list = roomService.findRoomByParam(req, param);
		String count = roomService.countRoomByParam(req, param);
		return new JsonObjectResult(count,list);
	}
	
	@ExceptionHandler(RoomNotFoundException.class)
	@ResponseBody
	public JsonObjectResult roomException(RoomNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(1010,e);
	}
}
